home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4722 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: How to tell if a file exists in C
  5. Date: Tue, 06 Feb 96 17:26:05 GMT
  6. Organization: none
  7. Message-ID: <823627565snz@genesis.demon.co.uk>
  8. References: <4eqkj6$ipo@charm.magnus.acs.ohio-state.edu> <m2pwbuvfb9.fsf@hawk.no>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <m2pwbuvfb9.fsf@hawk.no>
  15.            jan-henrik.haukeland@fou.telenor.no "jan-henrik haukeland" writes:
  16.  
  17. >Use the stat function, e.g.:
  18. >
  19. >#include <sys/stat.h>
  20. >#include <unistd.h>
  21. >
  22. >/* Check if file exists */
  23. >int fexist(char * filename)
  24. >{
  25. >  struct stat buf;
  26. >
  27. >  if (( stat (filename, &buf)) < 0)
  28. >    return (FALSE);
  29. >
  30. >  if (! S_ISREG(buf.st_mode)) {
  31. >    return (NOT_A_REGULAR_FILE);
  32. >  }
  33. >
  34. >  return(TRUE);
  35. >}
  36.  
  37. This function returns 3 distinct values. As such it does not return a
  38. voolean-like quantity. Therefore it is highly misleading to label two of
  39. those return values as TRUE and FALSE - you should find some more
  40. appropriate names.
  41.  
  42. -- 
  43. -----------------------------------------
  44. Lawrence Kirby | fred@genesis.demon.co.uk
  45. Wilts, England | 70734.126@compuserve.com
  46. -----------------------------------------
  47.